package cn.chen.utils;

import java.util.Optional;

public abstract class PageUtils {

    private static final ThreadLocal<Integer> PAGE_HOLDER = new ThreadLocal<>();
    private static final ThreadLocal<Integer> PAGE_SIZE_HOLDER = new ThreadLocal<>();

    public static void setPage(int page) {
        PAGE_HOLDER.set(page);
    }

    public static Integer getPage(Integer defaultPage) {
        return Optional.ofNullable(PAGE_HOLDER.get()).orElse(defaultPage);
    }

    public static void setPageSize(int pageSize) {
        PAGE_SIZE_HOLDER.set(pageSize);
    }

    public static Integer getPageSize(Integer defaultPageSize) {
        return Optional.ofNullable(PAGE_SIZE_HOLDER.get()).orElse(defaultPageSize);
    }

    public static void clear() {
        PAGE_HOLDER.remove();
        PAGE_SIZE_HOLDER.remove();
    }

}
